<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增-表与rpc接口映射关系')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-table-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">表：</label>
                <div class="col-sm-8">
                    <select id="tableId" name="tableId" class="form-control m-b">
                        <option value="0">请选择</option>
                    </select>
<!--                    <input name="tableId" class="form-control" type="text">-->
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">RPC接口：</label>
                <div class="col-sm-8">
                    <select id="interfaceId" name="interfaceId" class="form-control m-b">
                        <option value="0">请选择</option>
                    </select>
<!--                    <input name="interfaceId" class="form-control" type="text">-->
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "system/table"
        $("#form-table-add").validate({
            focusCleanup: true
        });

        $.operate.post(ctx + "system/interface/list",{},function(result){
            if (result.code === 0) {
                $("#interfaceId").html(createInterfaceOptionsHtml(result));
            }else{
                alert(result.msg);
            }
        });
        $.operate.post(ctx + "tool/gen/list",{},function(result){
            if (result.code === 0) {
                $("#tableId").html(createTableOptionsHtml(result));
            }else{
                alert(result.msg);
            }
        });
        function createInterfaceOptionsHtml(result){
            var html="";
            if(result.rows&&result.rows.length>0){
                for(var i = 0;i<result.rows.length;i++){
                    html+="<option value='"+result.rows[i].id+"'>"+result.rows[i].fullName+"</option>";
                }
            }
            return html;
        }
        function createTableOptionsHtml(result){
            var html="";
            if(result.rows&&result.rows.length>0){
                for(var i = 0;i<result.rows.length;i++){
                    html+="<option value='"+result.rows[i].tableId+"'>"+result.rows[i].tableName+"</option>";
                }
            }
            return html;
        }

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-table-add').serialize());
            }
        }
    </script>
</body>
</html>